#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

import os.path
from admin import *
from config import *
import cgi

form = cgi.FieldStorage()  

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value


# GET ADMIN CONTENT
adm=AdminCms()
print adm.getPageHeader()
print adm.getAdminMenu()

# GET CONFIG
cfg=Head()
cfg.getHeadTags(1)
data=cfg.getConfig()
url=data[u'url']

## GET LIST IMG
files_list=[]
for root, dirs, files in os.walk(Glob.SITE_PATH + u'img/'):
  for i in files:
    files_list.append(os.path.join(root, i))


print u"<tr><td colspan='3'><div id='active_page'><br/><h3>Liste des images disponible</h3><br/><br/><span id='upload_process'>Loading...<br/><img src='/img/loader.gif' /></span><span id='upload_result'></span><form method='post' action='uploadFile.py' enctype='multipart/form-data' target='hiddeniframe' onsubmit='startUpload()'><input type='file' name='filename'><input type='submit' value='Upload'></form><iframe name='hiddeniframe' src='' class='hiddenTag'></iframe>"

print u"<table border='0' cellpadding='0' cellspacing='0' align='center'>"

for img in files_list:
   img_name=os.path.basename(img)
   print u"<tr><td class='adminField'><a href='%simg/%s' target='_blank'>%s</a></td></tr>" % (url, img_name, img_name)

print u"</table><br/><br/><input type='button' onclick='editCSS()' value='Editer le CSS actif'>"

print u"</div></td></tr>"

print adm.getPagesList()
print adm.getPageFooter()
